package com.careercup.question.id19570669;

public class Solution {
	/**
	 * You are given a file (and you do not know how big the file is, 
	 * nor how big the lines in the file are). 
	 * Write an algorithm that will generate a random number 
	 * (which will be used to index into the file) 
	 * such that the output of lines will be roughly proportional? 
	 * That is if the file contained 4 lines, 
	 * and if I ran the program 1 million times I should get each line printed approximately 250K times.
	 * Reference: http://nedbatchelder.com/blog/201208/selecting_randomly_from_an_unknown_sequence.html
	 * @param args
	 */
	public static void main(String[] args) {
		String seq[] = {"seq1", "seq2", "seq3", "seq4", "seq5", "seq6", "seq7"}, it = null;
		for(int i = 0; i < seq.length; i++) {
			if(Math.floor(Math.random() * i) == 0)
				it = seq[i];
		}
		System.out.println("Random element chosen with equal probability is " + it);
	}
}
